package tongwentongshu.com.app.activityim;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.tencent.imsdk.TIMCallBack;
import com.tencent.imsdk.TIMFriendAllowType;
import com.tencent.imsdk.TIMFriendshipManager;
import com.tencent.imsdk.TIMManager;

import tencent.tls.platform.TLSLoginHelper;
import tongwentongshu.com.app.R;


/**
 * 类描述：
 * 创建人： 史强
 * 创建时间:2017/7/21 09:26
 */
public class LoginActivity extends Activity {


//    private String  identify = "83928625";
    private String identify = "18401770529";
//    private String  identify = "932741168";
//    private String  identify = "18618232623";
    private String tag = "shiqiang";
    private String userSig;
    private TextView tv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_login_im);
        tv = (TextView) findViewById(R.id.tv);
        TLSLoginHelper loginHelper = TLSLoginHelper.getInstance().init(getApplicationContext(),
                1400035890, 14232, identify);
//        loginHelper.setTimeOut(TLSConfiguration.TIMEOUT);
//        loginHelper.setLocalId(TLSConfiguration.LANGUAGE_CODE);
        loginHelper.setTestHost("", true);                   // 走sso

        //83928625 的userSig
//        userSig = "eJxlj81Og0AYRfc8BWFtzPx0*DHpgjbE0qKgdJLWDUEY6ETKTIexoMZ3V7GJJH7bc*69*T4M0zStbZRe50UhXlud6TfJLPPGtIB19Qel5GWW6wyr8h9kg*SKZXmlmRohJIQgAKYOL1mrecUvhos95NqITIyufMnGmd*K2XceE9eblnS8HuFdQJfhw5LIZBcfF-1KRpuU9s84EcOw3pwgRc7iLOxo7982e7-q13VY3ydxHTw1h*LgnfLg3UOqyZUjArV6hDYPGydOd1T6WPh0PpnU-MguPwFgI4xncELPTHVctKOAACQQYfBzlvFpfAFPAlzp";

        //18401770529的
//        userSig = "eJxlj0FPgzAAhe-8CsLZaAt0FBMPshmFDYgDwuaFIC3QzHUI7RSN-32KGpv4rt*X9-LeNV3XjXSVnJdVdZBcFGLsqKFf6gYwz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fVYw7nrDnhpeenh-s5n60bXoGFleNN1qgg7TOAiBtIwbFN91O1xGKhWncB40an3bRP72al6DPEwUKp69zVMBM7Tugjib*au2iHCeH7eLh0WwQ6nU*8Gkgb38uYXJyKPEcwf0KHUNquwFigknlOGvONa79QFT814w";


        // identifier为用户名，userSig 为用户登录凭证
        TIMManager.getInstance().login(identify, userSig, new TIMCallBack() {
            @Override
            public void onError(int code, String desc) {
                //错误码code和错误描述desc，可用于定位请求失败原因
                //错误码code列表请参见错误码表
                Log.d("shiqiang", "login failed. code: " + code + " errmsg: " + desc);
                System.out.println("wocBUGkle");
            }

            @Override
            public void onSuccess() {
                Log.d("shiqiang", "login succ");
                System.out.println("wochenggongkle");

                tv.setText("登录成功,获取用户名");

                UserInfo.getInstance().setId(identify);
                UserInfo.getInstance().setUserSig(userSig);

                setAddType();





            }
        });
//        TLSService.getInstance().getUserSig(id);


    }

    private void setAddType() {
        //设置自己的好友验证方式为需要验证
        TIMFriendshipManager.ModifyUserProfileParam param = new TIMFriendshipManager.ModifyUserProfileParam();
        param.setAllowType(TIMFriendAllowType.TIM_FRIEND_ALLOW_ANY);

        TIMFriendshipManager.getInstance().modifyProfile(param, new TIMCallBack() {
            @Override
            public void onError(int code, String desc) {
                //错误码code和错误描述desc，可用于定位请求失败原因
                //错误码code列表请参见错误码表
                Log.e(tag, "modifyProfile failed: " + code + " desc" + desc);
            }

            @Override
            public void onSuccess() {
                Log.e(tag, "modifyProfile succ");

                setResult(100);
                finish();//此处一定要调用finish()方法

            }
        });






    }

    @Override
    protected void onResume() {
        super.onResume();

        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                tv.setText(TIMManager.getInstance().getLoginUser());


            }
        });

    }
}
